package cn.lcsjsxy.yxc.multithreading;

/**
 * 使用同步机制将单例模式中的懒汉式改写为线程安全的
 */
public class BankTest {
}

class Bank{
    private static Bank instance=null;
    public static Bank getInstance(){
        synchronized (Bank.class){
            if(instance==null){
                instance=new Bank();
            }
        }

        //方式二
        if (instance==null) {
            synchronized (Bank.class) {
                if(instance==null)
                    instance=new Bank();
            }
        }
        return instance;
    }
}
